package main

import "fmt"

func main() {
	var numa int = 10
	var numb int = 20
	fmt.Println(numa, numb)
	numa, numb = exchangeNum(numa, numb)
	fmt.Println(numa, numb)
	fmt.Println("值交换第二种方法==============================")
	exchangeNum2(&numa, &numb)
	fmt.Println(numa, numb)
	fmt.Println("=======================================")
	var numc int = 30
	exchangeNum3(numa, numb, numc)
}

// 遍历函数中的可变参数
func exchangeNum3(args ...int) {
	for i, j := range args {
		fmt.Println("遍历所有参数", i, j)
	}
}

// 传地址
func exchangeNum2(a *int, b *int) {
	var temp int
	temp = *a
	*a = *b
	*b = temp
}

// 传数值
func exchangeNum(numa int, numb int) (int, int) {
	var temp int
	temp = numa
	numa = numb
	numb = temp
	return numa, numb
}
